local xp_mult = 1--[4] = {"AddSpellBranch", {{51314, 51313}, 1, 1}},

function LevelPlayer(pl, xpdata)
	ChatManager:SendToClient({Color( 100, 100, 255 ), "Congratulations, you are now level ", Color( 100, 255, 100 ), ""..xpdata[1][3].."", Color( 100, 100, 255 ), "!"}, pl)
	pl:EmitSound("devin/blackbetty/weapons/levelup.wav", 150, 100+math.random(-10,10))
	ParticleEffect( "impact_light_heal", pl:GetPos() + Vector(0, 0, 48), Angle(0,0,0), pl )
end

function AddXP(pl, amount, origin)
	local leveled_up = false
	local class = player_manager.GetPlayerClass(pl)
	local xpdata = MatchData.PlayerProgress[pl:SteamID()]
	print(MatchData.PlayerProgress)
	if(origin == nil)then
		origin = "bad guy"
	end
	if(xpdata[1][1]+amount >= xpdata[1][2])then
		local next_amount = xpdata[1][1]+amount - xpdata[1][2]
		xpdata[1][3] = xpdata[1][3] + 1
		xpdata[1][1] = next_amount
		xpdata[1][2] = xpdata[1][2] * ClassData.MultXP
		leveled_up = true
		
		for k, v in pairs(ClassData.LevelData[class])do
			if(v[2][2] == xpdata[1][3])then
				xpdata[2][k] = 0
				ChatManager:SendToClient({Color( 100, 100, 255 ), "You have unlocked the level ", Color( 100, 255, 100 ), ""..xpdata[1][3].."", Color( 100, 100, 255 ), " talent tier!"}, pl)
				break
			end
		end
		LevelPlayer(pl, xpdata)
		
		net.Start("SendPlayerProgress")
		net.WriteTable(MatchData.PlayerProgress[pl:SteamID()][2])
		net.Send(pl)
		
		net.Start( "SendPlayerXP" )
		net.WriteTable({xpdata[1][1], xpdata[1][2], amount, origin})
		net.Send(pl)
	else
		xpdata[1][1] = xpdata[1][1] + amount
		net.Start( "SendPlayerXP" )
		net.WriteTable({xpdata[1][1], xpdata[1][2], amount, origin})
		net.Send(pl)
	end
end

function SendXP(pl, _min, _max, amt, origin)
	net.Start( "SendPlayerXP" )
	net.WriteTable({_min, _max, amt, origin})
	net.Send(pl)
end
